<template>
  <BaseContainer>
    <aplid-base-crud ref="crud" class="w-100" v-bind="{...theConfig,...$attrs}">
      <template v-slot:menuColumn="{ row }">
        <el-button
          v-if="row.dataStatus && row.dataStatus !== '0'"
          @click="handleChange(row)"
          text
          type="warning">
          变更中
        </el-button>
      </template>

      <template v-slot:ArchivesDialog="{ row, show }">
        <Archives 
          @refresh="handleRefresh" 
          @refreshPage="handleRefreshPage" 
          @rechange="handleOperate"
          :api="baseConfig.api" 
          :detailConfig="baseConfig.detailConfig" 
          :key="show"
          :nowRowData="row">
        </Archives>
      </template>
    </aplid-base-crud>
    <el-dialog v-model="dialogVisible" title="数据变更" width="65%">
      <RechangeDetail v-if="dialogVisible" @refresh="handleRefresh" :batchNumber="nowData.dataStatus"></RechangeDetail>
    </el-dialog>
  </BaseContainer>
</template>
  
<script setup lang="ts">
import { baseConfig } from './config'
import Archives from './components/Archives/index.vue'
import RechangeDetail from '@/views/datacenter/components/DataGather/change/detail.vue'
import { editConfig } from '@/views/datacenter/comprehensiveQueries/utils/index'
import { cloneDeep } from 'lodash-es'

type Props = {
  isComprehensiveQueries?:boolean
}
let props = withDefaults(defineProps<Props>(),{
  isComprehensiveQueries:false
})
let theConfig :any= ref({})
if(baseConfig){
  let defaultConfig =cloneDeep(baseConfig)
  if(props.isComprehensiveQueries){
    theConfig.value = editConfig(defaultConfig)
  }else{
    theConfig.value = baseConfig
  }
}
const crud = ref()
const dialogVisible = ref(false)
let nowData: any = {}
//  处理刷新
const handleRefresh = (query) => {
  dialogVisible.value = false
  nextTick(() => {
    crud.value.refreshChange(query)
  })
}
const handleOperate = (type, row, title) => {
  nextTick(() => {
    crud.value.handleOperate(type, row, title)
  })
}
const handleRefreshPage = () => {
  nextTick(() => {
    crud.value.refreshChange({}, true)
  })
}
const handleChange = (row) => {
  nowData = row
  dialogVisible.value = true
}
defineExpose({
  handleRefresh
})
</script>
  
<style scoped></style>
  